using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;

namespace GameFramework.GameObjects
{
    /// <summary>
    /// This class represent a screen.
    /// </summary>
    public class Screen : GameObject
    {
        public Screen()
        {
            Children = new List<GameObject>();
        }

        /// <summary>
        /// Gets or sets the screen static game objects
        /// </summary>
        public List<GameObject> Children { get; protected set; }

        /// <summary>
        /// Gets a value indicating whether the back button is pressed.
        /// </summary>
        public bool IsBackButtonPressed
        {
            get { return GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed; }
        }

        /// <summary>
        /// Override to add screen activation logic
        /// </summary>
        public virtual void ScreenActivated()
        {
        }

        /// <summary>
        /// Override to add screen closing logic
        /// </summary>
        public virtual void ScreenClosing()
        {
        }

        /// <summary>
        /// Update all the static screen objects
        /// </summary>
        public override void Update()
        {
            base.Update();

            foreach (var child in Children)
            {
                child.Update();
            }
        }

        /// <summary>
        /// Draw all the static screen objects
        /// </summary>
        public override void Draw()
        {
            base.Draw();

            foreach (var child in Children)
            {
                child.Draw();
            }
        }

        /// <summary>
        /// Shot the keyboard input.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="description">The description.</param>
        /// <param name="result">The default text.</param>
        /// <param name="showKeyboardInputCallback">The callback method.</param>
        public void ShowKeyboardInput(string title, string description, string result, AsyncCallback showKeyboardInputCallback)
        {
            if (!Guide.IsVisible)
            {
                Guide.BeginShowKeyboardInput(
                    PlayerIndex.One,
                    title,
                    description,
                    result,
                    showKeyboardInputCallback,
                    null);
            }
        }
    }
}
